From 93c9f64157e4b5c0a823272d98ce8254c2aa51b2 Mon Sep 17 00:00:00 2001 From: robertl Date: Sat, 27 Jun 2009 04:52:07 +0000 Subject: [PATCH] Delbin and msvc improvements. Warning fixes. --- delbin.c | 95 +++++++++++++++++++++----------------- jeeps/gpsapp.c | 4 +- kml.c | 4 +- msvc/GPSBabel-msvc7.vcproj | 9 ++-- msvc/GPSBabel.vcproj | 12 +++-- naviguide.c | 8 ++-- v900.c | 3 ++ 7 files changed, 79 insertions(+), 56 deletions(-) diff --git a/delbin.c b/delbin.c index 1ce239a7a..cf60ff9c6 100644 --- a/delbin.c +++ b/delbin.c @@ -522,56 +522,67 @@ message_write(unsigned msg_id, message_t* m) warning(MYNAME ": sent %x\n", msg_id); } +// read from the payload of a single packet +static unsigned +read_depacketize_1(gbuint8** p, unsigned n, int new_packet) +{ + static gbuint8 buf[256]; + static unsigned buf_i, buf_n; + while (buf_n == 0 || new_packet) { + packet_read(buf); + if (buf[1] <= delbin_os_packet_size - 2) { + buf_n = buf[1]; + buf_i = 2; + } + } + *p = buf + buf_i; + if (n > buf_n) { + n = buf_n; + } + buf_n -= n; + buf_i += n; + return n; +} + +// read from packet payloads until request is fulfilled +static void +read_depacketize(gbuint8* buf, unsigned n) +{ + while (n) { + gbuint8* p; + unsigned nn = read_depacketize_1(&p, n, FALSE); + memcpy(buf, p, nn); + n -= nn; + buf += nn; + } +} + // Get one valid message. // If a corrupted message with the right id is seen, return failure (0). static unsigned message_read_1(unsigned msg_id, message_t* m) { - gbuint8 buf[256]; - static gbuint8 buf_prev[256]; - gbuint8* p; - unsigned total = 0; - unsigned count = 0; - unsigned id = 0; - + unsigned id; for (;;) { - for (;;) { - unsigned n; - // if last packet had extra data - if (buf_prev[1]) { - // try that first - n = buf_prev[1] + 2; - memcpy(buf, buf_prev, n); - buf_prev[1] = 0; - } else { - n = packet_read(buf); - } - if (n >= 10 && buf[2] == 0xdb && buf[3] == 0xfe && - checksum(buf + 2, 6) == le_readu16(buf + 8)) - { - break; - } + unsigned total; + gbuint8 buf[8]; + gbuint8* p; + + read_depacketize(buf, 8); + while (buf[0] != 0xdb || buf[1] != 0xfe || checksum(buf, 6) != le_readu16(buf + 6)) { + gbuint8* pp; + // try for a message start at the beginning of next packet + read_depacketize_1(&pp, 8, TRUE); + memcpy(buf, pp, 8); } - count = buf[1] - 8; - total = le_readu16(buf + 6); - id = le_readu16(buf + 4); + id = le_readu16(buf + 2); + total = le_readu16(buf + 4); message_ensure_size(m, total - 4); - memcpy(m->buf, buf, 2 + buf[1]); - while (count < total) { - unsigned n; - packet_read(buf); - n = buf[1]; - // if packet has more than needed to complete message - if (n > total - count) { - const unsigned n_next = n - (total - count); - n -= n_next; - // save the rest for next time - memcpy(buf_prev + 2, buf + 2 + n, n_next); - buf_prev[1] = n_next; - } - memcpy((char*)m->data + count, buf + 2, n); - count += n; - } + // copy in message head, really only need id field, do the rest for debugging + m->buf[0] = m->buf[1] = 0; + memcpy(m->buf + 2, buf, 8); + // read message body and trailer + read_depacketize(m->data, total); p = (gbuint8*)m->data + m->size; if (checksum(m->data, m->size) == le_readu16(p) && p[2] == 0xad && p[3] == 0xbc) diff --git a/jeeps/gpsapp.c b/jeeps/gpsapp.c index d87520e50..93f7d8caa 100644 --- a/jeeps/gpsapp.c +++ b/jeeps/gpsapp.c @@ -4301,7 +4301,7 @@ void GPS_D301_Send(UC *data, GPS_PTrack trk, int type) p+=sizeof(float); if (type == 302) { - GPS_Util_Put_Float(p,1.0e25); + GPS_Util_Put_Float(p, 1.0e25f); p+=sizeof(float); } @@ -4321,7 +4321,7 @@ void GPS_D304_Send(UC *data, GPS_PTrack trk) GPS_Util_Put_Float(p,trk->alt); p+=sizeof(float); - GPS_Util_Put_Float(p, (const float) 1.0e25); + GPS_Util_Put_Float(p, 1.0e25f); p+=sizeof(float); /* Not really clear if the members below makes sense to write or not */ diff --git a/kml.c b/kml.c index b3847c263..66c7cf192 100644 --- a/kml.c +++ b/kml.c @@ -1080,6 +1080,8 @@ static void kml_route_tlr(const route_head *header) // the bounding box of our entire data set and set the event times // to include all our data. void kml_write_AbstractView(void) { + double bb_size; + kml_write_xml(1, "\n"); if (kml_time_min || kml_time_max) { @@ -1115,7 +1117,7 @@ void kml_write_AbstractView(void) { // It turns out the length of the diagonal of the bounding box gives us a // reasonable guess for setting the camera altitude. - double bb_size = gcgeodist(kml_bounds.min_lat, kml_bounds.min_lon, + bb_size = gcgeodist(kml_bounds.min_lat, kml_bounds.min_lon, kml_bounds.max_lat, kml_bounds.max_lon); // Clamp bottom zoom level. Otherwise, a single point zooms to grass. if (bb_size < 1000) { diff --git a/msvc/GPSBabel-msvc7.vcproj b/msvc/GPSBabel-msvc7.vcproj index afe9eba6c..1c233077c 100644 --- a/msvc/GPSBabel-msvc7.vcproj +++ b/msvc/GPSBabel-msvc7.vcproj @@ -39,7 +39,7 @@ Name="VCCustomBuildTool"/> + + + RelativePath="..\pocketfms_bc.c"> diff --git a/msvc/GPSBabel.vcproj b/msvc/GPSBabel.vcproj index 2f5561841..1e57a4b53 100644 --- a/msvc/GPSBabel.vcproj +++ b/msvc/GPSBabel.vcproj @@ -78,7 +78,7 @@ /> + + @@ -2688,7 +2692,7 @@ RelativePath="..\pocketfms_fp.c"> + RelativePath="..\pocketfms_bc.c"> diff --git a/naviguide.c b/naviguide.c index bf529874f..82c530a98 100755 --- a/naviguide.c +++ b/naviguide.c @@ -302,10 +302,9 @@ wr_init(const char *fname) { } static void -wr_deinit () { +wr_deinit(void) +{ gbfclose(file_out); - - } /*=========================== Read data functions ==================================*/ @@ -354,7 +353,8 @@ ng_read_file_header(void) static void data_read(void) { - int n, i; + int n; + unsigned i; waypoint *wpt_tmp; if (process_rte) { diff --git a/v900.c b/v900.c index d6887ef92..083b73bc0 100644 --- a/v900.c +++ b/v900.c @@ -74,6 +74,9 @@ for a little more info, see structures: #include #include +#if _MSC_VER + #define __func__ __FUNCTION__ +#endif /* the start of each record (line) is common to both advanced and basic mode. it will be parsed by a single common code. hence, it will be easier and clearer -- 2.30.2